<template>
<h2>注册</h2>
<table>
    <tr>
        <td>姓名</td>
        <td>
            <input type="text" v-model="m.mname"/>
        </td>
    </tr>
    <tr>
        <td>卡号</td>
        <td>
            <input type="text" v-model="m.mcard"/>
        </td>
    </tr>
    <tr>
        <td>手机号</td>
        <td>
            <input type="text" v-model="m.phone"/>
        </td>
    </tr>
    <tr>
        <td>生日</td>
        <td>
            <input type="date" v-model="m.birday"/>
        </td>
    </tr>
    <tr>
        <td>消费金额</td>
        <td>
            <input type="text" v-model="m.moneys"/>
        </td>
    </tr>
    <tr>
        <td>身份证号</td>
        <td>
            <input type="text" v-model="m.idcard"/>
        </td>
    </tr>
    <tr>
        <td>登记时间</td>
        <td>
            <input type="date" v-model="m.cdate"/>
        </td>
    </tr>
    <tr>
        <td>会员类型</td>
        <td>
            <select v-model="m.mebertype"> 
                <option>普通会员</option>
                <option>银卡会员</option>
                <option>金卡会员</option>
                <option>钻石会员</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="注册" @click="Add"/>
        </td>
    </tr>
</table>


</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'

const m=ref({
    mcard:'',
    mname:'',
    phone:'',
    birday:'',
    moneys:'',
    idcard:'',
    cdate:'',
    mebertype:''
})

const Add=()=>{
    var obj={
        mcard:m.value.mcard,
        mname:m.value.mname,
        phone:m.value.phone,
        birday:m.value.birday,
        moneys:m.value.moneys,
        idcard:m.value.idcard,
        cdate:m.value.cdate,
        mebertype:m.value.mebertype
    }
    if(!obj.mname){
        alert("姓名不能为空");
        return;
    }
    if(!obj.mcard){
        alert("会员卡号不能为空");
        return;
    }
    if(!obj.phone){
        alert("手机号不能为空");
        return;
    }
    if(!obj.birday){
        alert("生日不能为空");
        return;
    }
    if(!obj.idcard){
        alert("身份证不能为空");
        return;
    }
    if(obj.idcard.length!=18){
        alert("身份证只能是18位");
        return;
    }
    axios.post('https://localhost:7113/api/Meber/MeberAdd',obj)
    .then(res=>{
        if(res.data==-1){
            alert("手机号重复请重新输入");
        }
        else if(res.data>0){
            alert("注册成功");
        }
        else{
            alert("注册失败");
        }
    })
    .catch(err=>{
        alert(err);
    })
}


</script>

